package org.icress.fusion.ws

import cxf.client.dcms.YiFeiGatewayService

class GetCalloutResponseService {

    static transactional = false 

    //定义Webservice
    def yiFeiGatewayService

    def decipherResponseService

    def fire(Long outBoundMessageId){
        log.info("GetCalloutResponseService.fire(${outBoundMessageId})")
        //获取出站消息
        def outBoundMessage = OutBound.get(outBoundMessageId)
        //出站消息ID不存在，退出
        if(!outBoundMessage){
            return;
        }        
        try{
            //准备XML
            def inputXml = """
                <STD_IN Origin="WOS">
                    <Service Name="GetJobStatus">
                        <JobID>${outBoundMessage.jobId}</JobID>
                    </Service>
                </STD_IN>
            """
            //取JOB状态
            def outputXml = yiFeiGatewayService.yifeiGateway( inputXml)
            def result = decipherResponseService."${outBoundMessage.method}"(outBoundMessage.objectId, outputXml, true)
            //更新outBound Message
            outBoundMessage.jobStatus = result.get("JobStatus")
            outBoundMessage.jobError = result.get("JobError")
            outBoundMessage.jobResult = result.get("JobResult")
            outBoundMessage.retryGet = (outBoundMessage.retryGet?:0) + 1
        }catch(e){
            outBoundMessage.result = e.toString()
            outBoundMessage.retryGet = (outBoundMessage.retryGet?:0) + 1
            outBoundMessage.retryGetError = (outBoundMessage.retryGetError?:0) + 1
        }
        outBoundMessage.save(flash:true)
    }  
}
